package com.taijia.chapter9;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 2015/2/3
 * Time: 22:24
 * To change this template use File | Settings | File Templates.
 */
public class TestStop {
    public static void main(String[] args) {
        Runner r = new Runner();
        Thread t = new Thread(r);
        t.start();
        for (int i=0;i<100;i++)
            System.out.println("main thread:"+i);
        System.out.println("main thread is over!");
        System.out.println(Thread.currentThread().getName());
        r.shutDown(); // run一结束，线程就结束
    }
}

class Runner implements Runnable {
    private boolean flag = true;

    @Override
    public void run() {
        int i = 0;
        while (flag) {
            System.out.println("thread:"+ ++i);
        }
        System.out.println(Thread.currentThread().getName());
    }

    public void shutDown() {
        this.flag = false;
    }
}
